using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using FluorineFx;
using FluorineFx.AMF3;
using SharedCloud;

namespace CerasusServices
{
    [RemotingService]
    public class WorkspaceService
    {
        protected static Cloud cloud;
        protected static RevisionTracker tracker;

        static WorkspaceService()
        {
            try
            {
                cloud = new Cloud("Workspace");
                tracker = new RevisionTracker(cloud.FetchAll());
            }
            catch (Exception) { }
        }

        public ASObject fetch(int lastRevision)
        {
            return tracker.Update(lastRevision);
        }

        public void update(ASObject header)
        {
            try
            {
                tracker.Commit(header);
                cloud.Persist(header);
            }
            catch (Exception) { }
        }

        public ASObject getSession()
        {
            Random rnd = new Random();

            ASObject session = new ASObject("SharedCloud::Session");
            session["serverID"] = 0;
            session["clientID"] = rnd.Next();

            return session;
        }
    }
}